package com.avengers.mobile.layer.daoimpl;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;

import com.avengers.mobile.layer.dao.PedidoDao;
import com.avengers.mobile.layer.hibernate.HibernateGenericDAOImpl;
import com.avengers.mobile.layer.model.Pedido;
import com.avengers.mobile.layer.model.PedidoDetalle;

@Repository("beanPedidoDao")
@Scope("prototype")
public class PedidoDaoImpl extends HibernateGenericDAOImpl implements PedidoDao {

	private Logger logger = Logger.getLogger(this.getClass());

	@Autowired
	public PedidoDaoImpl(
			@Qualifier("hibernateTemplate") HibernateTemplate hibernateTemplate) {
		logger.debug("Entrando a " + this.getClass().getName()
				+ ".EquipoDaoImpl");
		this.setHibernateTemplate(hibernateTemplate);

	}

	@SuppressWarnings("rawtypes")
	public int save(Pedido pedido) throws Exception {
		super.save(pedido);
		List list = super.getSession()
				.createQuery(" select max(p.idPedido) from Pedido as p ")
				.list();
		return (Integer) list.get(0);
	}

	public int saveDetalle(PedidoDetalle detalle) throws Exception {
		super.save(detalle);
		return detalle.getIdPedido_Detalle();
	}

	public List<Pedido> findPedidoList(Object[] params) throws Exception {
		return super.find(" from Pedido as p where p.usuario= ? ",params);
	}
	
	public List<PedidoDetalle>findPedidoDetalleList(Object[] params) throws Exception {
		return super.find(" from PedidoDetalle as p where p.pedido= ?",params);
	}

}